#define ADPM_USER
#include "../user.h"


int main(){
  int size = 10*(1<<10), i;
  struct adpm_mem *mem;
  int *addr;
  char dir[100] = "./adpm/a";
  int a,b,c;
  for(;;){
    char op[100];
    scanf("%s",op);
    switch(op[0]){
    case 'd':
      scanf("%d%d", &a, &b);
      if(adpm_user_make_dirty(mem, addr + a, b)){
	printf("dirty fialed\n");
      }else printf("dirty!");
      break;
    case 'n':
      scanf("%s", dir);
      break;
    case 'g':
      mem=adpm_user_get_mempool(dir, size);
      addr = mem->addr;
      printf("get mempool Addr:%lx \n", addr);
      break;
    case 's':
      scanf("%d", &size);
      printf("size change to %d, max %d int\n", size, size>>2);
      break;
    case 'r':
      scanf("%d", &a);
      printf("addr[%d] = %d\n",a , addr[a]);
      break;
    case 'w':
      scanf("%d", &a);
      addr[a] = 1;
      printf("write addr[%d] = %d\n", a, addr[a]);
      break;
    case 'p':
      adpm_user_put_mempool(mem);
      break;
    case 'x':
      printf("begin check\n");
      for(i=0;i*4<size;i++){
        if(addr[i]!=i){
          printf("addr[%d]=%d\n",i,addr[i]);
        }
      }
      printf("finish check\n");
      break;
    }
  }
  return 0;
}

